/**
 * 
 */
package org.vectrics.recruiter.user.event;

import java.util.Locale;

import org.vectrics.common.util.DateUtil;
import org.vectrics.employee.Employee;
import org.vectrics.event.Event;
import org.vectrics.event.EventEmailBuilder;
import org.vectrics.mail.EmailHtmlBase;
import org.vectrics.mail.MailMessage;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.job.event.InterviewHtmlEmail;

/**
 * @author pgoette
 * Costructor del mail a enviar en caso de ser contratada una persona.
 */
public class HiredEmailBuilder extends EventEmailBuilder {
 
	/**
	 * Persona empleada por la cual hay que notificar.
	 */
	private Employee employee = null;
	
	public HiredEmailBuilder(Event event, Locale locale, Employee employee) {
		super(event, locale);
		this.setEmployee(employee);
	}

	/* (non-Javadoc)
	 * @see org.vectrics.event.EventEmailBuilder#createHtmlEmail()
	 */
	@Override
	protected EmailHtmlBase createHtmlEmail() {
		HiredHtmlEmail email = new HiredHtmlEmail(this.getLocale(), this.getEmployee());
		return(email);
	}

	/* (non-Javadoc)
	 * @see org.vectrics.event.EventEmailBuilder#getEmailFromName()
	 */
	@Override
	protected String getEmailFromName() {
		String from = CoreServiceLocator.getSystemService().getStringSystemConstant("mail.from.name", employee.getCompany().getDomain());
		return(from);
	}

	/* (non-Javadoc)
	 * @see org.vectrics.event.EventEmailBuilder#getSubject()
	 */
	@Override
	public String getSubject() {
		String subject = this.getPhrase("email.subject.hired.person") +  
		                 this.getEmployee().getPerson().getFullName();
	    return(subject);
	}

	/* (non-Javadoc)
	 * @see org.vectrics.event.EventEmailBuilder#getTextMailMessage()
	 */
	@Override
	public MailMessage getTextMailMessage() {
		MailMessage message = new MailMessage(this.getDomain());
		message.setContentType(MailMessage.CONTENT_TEXT);
		String dateStart = DateUtil.getFechaFormateada(this.getEmployee().getDateStart());
		Object[] args = { 
				this.getEmployee().getPerson().getFullName() , 
				dateStart
		};
		message.setBody(this.getPhrase("email.body.hired.person", args) );
		message.setFromName(this.getEmailFromName());
		message.setSubject(this.getSubject());
		return(message);
	}

	/* (non-Javadoc)
	 * @see org.vectrics.event.EventEmailBuilder#supportsHtml()
	 */
	@Override
	public boolean supportsHtml() {
		return true;
	}

	/**
	 * @return the employee
	 */
	public Employee getEmployee() {
		return employee;
	}

	/**
	 * @param employee the employee to set
	 */
	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

}
